home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 7.6 KB | 265 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWEmbUtl.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWEMBUTL_H
- #include "FWEmbUtl.h"
- #endif
-
- #ifndef FWFILESP_H
- #include "FWFileSp.h"
- #endif
-
- #ifndef FWACQUIR_H
- #include "FWAcquir.h"
- #endif
-
- #ifndef FWBARRAY_H
- #include "FWBArray.h"
- #endif
-
- #ifndef FWCLNINF_H
- #include "FWClnInf.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWINTER_H
- #include "FWInter.h"
- #endif
-
- #ifndef SLODFSTR_K
- #include "SLODFStr.k"
- #endif
-
- #ifndef SLODFSTR_H
- #include "SLODFStr.h"
- #endif
-
- #ifndef FWALERT_H
- #include "FWAlert.h"
- #endif
-
- #ifndef FWSESION_H
- #include "FWSesion.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODDraft_xh
- #include <Draft.xh>
- #endif
-
- #ifndef SOM_ODDraft_xh
- #include <Draft.xh>
- #endif
-
- #ifndef SOM_ODDocument_xh
- #include <Document.xh>
- #endif
-
- #ifndef SOM_ODStorageSystem_xh
- #include <ODStor.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
- //========================================================================================
- // Runtime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fw_embedding
- #endif
-
- //========================================================================================
- // Global Methods
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_AcquireFileContainer
- //----------------------------------------------------------------------------------------
-
- ODContainer* FW_AcquireFileContainer(Environment* ev, const FW_PFileSpecification& fileSpec)
- {
- #ifdef FW_BUILD_MAC
- FSSpec macSpec;
- fileSpec->MacGetFSSpec(ev, &macSpec);
-
- FW_CByteArray bArray(&macSpec, sizeof(short) + sizeof(long) + macSpec.name[0] + 1);
- return FW_CSession::GetStorageSystem(ev)->AcquireContainer(ev, kODDefaultFileContainer, bArray);
- #endif
-
- #ifdef FW_BUILD_WIN
- FW_DEBUG_MESSAGE("Not Yet Implemented");
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_InsertPartFromFile
- //----------------------------------------------------------------------------------------
-
- FW_EInternalizeResult FW_InsertPartFromFile(Environment* ev,
- FW_CEmbeddingFrame* frame,
- const FW_PFileSpecification& fileSpec)
- {
- FW_EInternalizeResult result = FW_kInternalizeFailed;
-
- FW_CAcquiredODContainer aqContainer = ::FW_AcquireFileContainer(ev, fileSpec);
- if (aqContainer != NULL)
- {
- // ----- Get the document -----
- FW_CAcquiredODDocument documentToInsert = aqContainer->AcquireDocument(ev, kODDefaultDocument);
- /*
- // [HLX] There is no way to test that I am trying to insert the same document. The following code
- // doesn't work.
-
- // ----- Check we are not trying to insert itself -----
- ODID id1 = frame->GetPart(ev)->GetDraft(ev)->GetDocument(ev)->GetID(ev);
- ODID id2 = documentToInsert->GetID(ev);
- if (id2 == id1)
- {
- FW_CString errorStr;
- FW_CString32 partName;
- frame->GetPart(ev)->GetPartName(ev, partName);
- FW_PrivLoadODFString(ev, FW_kInsertSameDocument, errorStr);
- FW_ErrorAlert(partName, errorStr);
- return result;
- }
- */
- // ----- Get the draft -----
- FW_CAcquiredODDraft fromDraft = documentToInsert->AcquireBaseDraft(ev, kODDPReadOnly);
-
- while (documentToInsert->Exists(ev, 0, fromDraft, kODPosLastAbove))
- {
- fromDraft = documentToInsert->AcquireDraft(ev,
- kODDPReadOnly,
- NULL,
- fromDraft,
- kODPosLastAbove,
- FALSE);
- }
-
- FW_CAcquiredODStorageUnit fromSU = fromDraft->AcquireDraftProperties(ev);
-
- fromSU->Focus(ev, kODPropRootPartSU, kODPosUndefined, kODStrongStorageUnitRef, 0, kODPosUndefined);
-
- ODStorageUnitRef aSURef;
- FW_CByteArray byteArray;
- fromSU->GetValue(ev, sizeof(aSURef), byteArray);
- byteArray.CopyBuffer( &aSURef, sizeof(aSURef));
-
- FW_CAcquiredODStorageUnit aqInsertSU = fromDraft->AcquireStorageUnit(ev, fromSU->GetIDFromStorageUnitRef(ev, aSURef));
-
- FW_CPresentation* presentation = frame->GetPresentation(ev);
-
- // ----- Embed -----
- ODPasteAsResult embedInfo;
-
- embedInfo.pasteLinkSetting = FALSE;
- embedInfo.autoUpdateSetting = FALSE;
- embedInfo.mergeSetting = FALSE;
- embedInfo.selectedView = presentation->GetDefaultEmbeddedFrameViewType(ev);
- embedInfo.selectedKind = NULL;
- embedInfo.translateKind = NULL;
- embedInfo.editor = kODNoEditor;
-
- FW_CPart* part = presentation->GetPart(ev);
- FW_CSelection* selection = presentation->GetSelection(ev);
- result = part->GetDataInterchange(ev)->InternalizeData(ev, selection->GetSelectedContent(ev), frame, aqInsertSU, FW_kFileStorage, kODClonePaste, &embedInfo);
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_ClonePartFromFile
- //----------------------------------------------------------------------------------------
-
- ODPart* FW_ClonePartFromFile(Environment* ev, FW_CEmbeddingFrame* scopeFrame, const FW_PFileSpecification& fileSpec)
- {
- FW_ASSERT(scopeFrame);
-
- ODDraft* destDraft = scopeFrame->GetPart(ev)->GetDraft(ev);
-
- ODPart* clonedPart = NULL;
-
- FW_CAcquiredODContainer aqContainer = ::FW_AcquireFileContainer(ev, fileSpec);
- if (aqContainer != NULL)
- {
- // ----- Get the document -----
- FW_CAcquiredODDocument documentToInsert = aqContainer->AcquireDocument(ev, kODDefaultDocument);
-
- // ----- Get the draft -----
- FW_CAcquiredODDraft fromDraft = documentToInsert->AcquireBaseDraft(ev, kODDPReadOnly);
-
- while (documentToInsert->Exists(ev, 0, fromDraft, kODPosLastAbove))
- {
- fromDraft = documentToInsert->AcquireDraft(ev,
- kODDPReadOnly,
- NULL,
- fromDraft,
- kODPosLastAbove,
- FALSE);
- }
-
- FW_CAcquiredODStorageUnit fromSU = fromDraft->AcquireDraftProperties(ev);
-
- fromSU->Focus(ev, kODPropRootPartSU, kODPosUndefined, kODStrongStorageUnitRef, 0, kODPosUndefined);
-
- ODStorageUnitRef aSURef;
- FW_CByteArray byteArray;
- fromSU->GetValue(ev, sizeof(aSURef), byteArray);
- byteArray.CopyBuffer( &aSURef, sizeof(aSURef));
-
- FW_CAcquiredODStorageUnit aqInsertSU = fromDraft->AcquireStorageUnit(ev, fromSU->GetIDFromStorageUnitRef(ev, aSURef));
-
- FW_CCloneInfo cloneInfo(ev, fromDraft, scopeFrame, kODClonePaste);
- cloneInfo.BeginClone(ev, destDraft);
-
- ODID clonedPartID = cloneInfo.Clone(ev, aqInsertSU->GetID(ev), 0, 0);
- FW_ASSERT(clonedPartID != kODNULLID);
-
- cloneInfo.EndClone(ev);
-
- clonedPart = destDraft->AcquirePart(ev, clonedPartID);
- }
-
- return clonedPart;
- }
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_MacInsertFilterProc
- //----------------------------------------------------------------------------------------
-
- pascal Boolean FW_MacInsertFilterProc(CInfoPBPtr pb)
- {
- FInfo* finderInfo = &pb->hFileInfo.ioFlFndrInfo;
- // remenber: TRUE suppresses display, FALSE allows display
- #if 0
- return (finderInfo->fdCreator != 'odtm') || // otdm creator
- ((finderInfo->fdFlags & 0xE000) != 0) || // visible
- (finderInfo->fdType == 'APPL'); // Not an application
- #endif
- return (((finderInfo->fdFlags & 0xE000) != 0) || // visible
- (finderInfo->fdType == 'APPL')); // Not an application
-
- }
- #endif
-